'use strict';

module.exports = app => {
  const { STRING, INTEGER, DATE } = app.Sequelize;

  const IdleCategory = app.model.define('idle_category', {
    id: { type: INTEGER, primaryKey: true, autoIncrement: true },
    name: { type: STRING(50), allowNull: false, comment: '分类名称' },
    parent_id: { type: INTEGER, defaultValue: 0, comment: '父级ID，0表示顶级分类' },
    type: { type: STRING(20), allowNull: false, comment: '分类类型：物资(物资)、设备(设备)' },
    sub_type: { type: STRING(50), comment: '子类型，如主材/辅材/周材，盾构机/管片运输车等' },
    sort: { type: INTEGER, defaultValue: 0, comment: '排序' },
    create_time: { type: DATE, defaultValue: app.Sequelize.fn('NOW') },
    update_time: { type: DATE, defaultValue: app.Sequelize.fn('NOW') }
  }, {
    tableName: 'idle_category',
    timestamps: false,
  });

  // 定义关联关系
  IdleCategory.associate = function() {
    app.model.IdleCategory.hasMany(app.model.IdleItem, { foreignKey: 'category_id' });
  };

  return IdleCategory;
};
